package com.xbongbong.saas.model;

import com.xbongbong.paas.toolbox.exception.XbbException;
import com.xbongbong.paas.toolbox.wrap.IModel;
import com.xbongbong.saas.domain.entity.MarketActivityUserEntity;
import com.xbongbong.saas.domain.entity.UserTeamEntity;
import org.elasticsearch.action.support.WriteRequest;

import java.util.List;
import java.util.Map;
import java.util.Set;

/**
 * @author chunyang.qin
 * @version v1.0
 * @date 2020/11/4 10:18
 * @since v1.0
 */
public interface MarketActivityUserModel extends IModel<MarketActivityUserEntity> {

    /**
     * 获取符合查询条件的记录
     *
     * @param param 查询条件
     * @return java.util.List<com.xbongbong.saas.domain.entity.MarketActivityUserEntity>
     * @author chunyang.qin
     * @date 2020/11/4 14:22
     */
    @Override
    List<MarketActivityUserEntity> findEntitys(Map<String, Object> param);

    /**
     * 保存实体
     *
     * @param MarketActivityUserEntity 市场活动协同人团队实体
     * @return java.lang.Integer
     * @throws XbbException 数据库异常
     * @author chunyang.qin
     * @date 2019/2/14 16:42
     */
    Integer save(MarketActivityUserEntity MarketActivityUserEntity) throws XbbException;

    /**
     * 获取单个实体
     *
     * @param key    id主键
     * @param corpid 公司id
     * @return com.xbongbong.saas.domain.entity.MarketActivityUserEntity
     * @author chunyang.qin
     * @date 2019/2/14 16:43
     */
    MarketActivityUserEntity getByKey(Long key, String corpid);

    /**
     * Description: 获取客户负责人/协同人的id
     * @param corpid 公司id
     * @param marketActivityIds 市场活动id
     * @param isMain 是否为负责人 1 负责人 0协同人 null所有负责人合协同人
     * @return java.util.List<java.lang.String> 客户负责人/协同人id
     * @author 魏荣杰
     * @date 2019/2/18 14:43
     * @since v1.0
     * Modified by:
     */
    List<String> getMarketActivityUserIdList(String corpid, List<Long> marketActivityIds, Integer isMain);
    /**
     * Description: 获取客户负责人/协同人的id
     * @param corpid 公司id
     * @param marketActivityId 市场活动id
     * @param isMain 是否为负责人 1 负责人 0协同人 null所有负责人合协同人
     * @return java.util.List<java.lang.String> 客户负责人/协同人id
     * @author 吴峰
     * @date 2021-07-26 17:04 
     * @since v1.0
     * Modified by:
     */
    List<MarketActivityUserEntity> getMarketActivityUserList(String corpid, Long marketActivityId, Integer isMain);
    /**
     * 获取协同团队的业务数据
     * @param corpid 公司id
     * @param isMain 负责或协同
     * @param userId 用户id
     * @return List<Long>
     */
    List<Long> getDataIdList(String corpid, Integer isMain, List<String> userId);
    

    /**
     * 协同人批量升级
     * @param corpid
     * @param customerUsers
     */
    void batchUpgrade(String corpid, List<MarketActivityUserEntity> customerUsers, WriteRequest.RefreshPolicy refreshPolicy) throws XbbException;

    /**
     * 批量删除
     * @param corpid
     * @param customerUsers
     * @param del
     * @param refreshPolicy
     */
    void deleteBatch(String corpid, List<MarketActivityUserEntity> customerUsers, WriteRequest.RefreshPolicy refreshPolicy, Integer del) throws XbbException;

    /**
     * 批量插入
     * @param marketActivityUserEntity
     */
    void insertBatch(List<MarketActivityUserEntity> marketActivityUserEntity, boolean isImport) throws XbbException;

    /**
     * 批量剔除团队
     * @param corpid
     * @param marketActivityIdList 市场活动id
     * @param userIdList
     */
    void batchDeleteByMarketActivityId(String corpid, List<Long> marketActivityIdList, List<String> userIdList) throws XbbException;

    void batchDeleteTeam(String corpid, List<Long> customerIdList, List<String> userIdList, WriteRequest.RefreshPolicy refreshPolicy) throws XbbException;

    /**
     * 批量剔除团队
     * @param corpid
     * @param removeIdList 市场活动团队表idList
     */
    Map<Long, Set<String>> batchDeleteById(String corpid, List<Long> removeIdList, WriteRequest.RefreshPolicy refreshPolicy) throws XbbException;

    /**
     * 删除团队成员
     * @param marketActivityUser
     */
    void delete(MarketActivityUserEntity marketActivityUser) throws XbbException;

    /**
     * 查询基础列表
     * @param map
     * @return
     */
    List<UserTeamEntity> findBaseEntitys(Map<String, Object> map);

    /**
     * 批量更新
     * @author chunyang.qin
     * @date 2020/11/4 18:59
     * @param list
     * @param corpid 公司id
     * @return java.lang.Integer
     */
    Integer updateBatch(List<MarketActivityUserEntity> list, String corpid) throws XbbException;


    /**
     * 批量更新团队状态
     *
     * @param corpid
     * @param dataIdIn
     * @param userTeamEntityList
     * @param isMain
     * @throws XbbException
     */
    void batchUpdateByUserIdIn(String corpid, List<Long> dataIdIn, List<UserTeamEntity> userTeamEntityList, Integer isMain, Integer del) throws XbbException;

    void batchUpdateByUserIdIn(String corpid, List<Long> dataIdIn, List<UserTeamEntity> userTeamEntityList, Integer isMain, Integer del, WriteRequest.RefreshPolicy refreshPolicy) throws XbbException;

    /**
     * 编辑团队成员标签
     *
     * @param marketActivityUserEntity
     */
    void editLabel(MarketActivityUserEntity marketActivityUserEntity) throws XbbException;

    /**
     * 更新协同人可编辑权限
     *
     * @param marketActivityUserEntity
     */
    void updateEditFormPer(MarketActivityUserEntity marketActivityUserEntity) throws XbbException;

    /**
     * 更新团队协同人信息和协同人可编辑权限
     *
     * @param corpid
     * @param idIn
     * @param updateUserToCoTeamList
     * @param coopUser
     * @param needThrow
     */
    void batchUpdateCoAndPerByUserIdIn(String corpid, List<Long> idIn, List<UserTeamEntity> updateUserToCoTeamList, Integer coopUser, boolean needThrow) throws XbbException;

    void batchUpdateCoAndPerByUserIdIn(String corpid, List<Long> idIn, List<UserTeamEntity> teamEntityList, Integer isMain, boolean needThrow, WriteRequest.RefreshPolicy refreshPolicy) throws XbbException;
}
